<template>
  <div>
    <HeaderComponent @enterTip="onSearch" @changeTip="onSearch"></HeaderComponent>
    <SList :list="list" style="position: relative;top: 66px;"></SList>
  </div>
</template>
<script>
import HeaderComponent from 'components/header'
import SList from 'components/shangjia-list'
import {mapGetters} from 'vuex'
export default {
  name: 'search',
  components: {
    HeaderComponent,
    SList
  },
  data(){
    return{
      list: []
    }
  },
  computed:{
    ...mapGetters([
      'getLocation'
    ])
  },
  methods:{
    // 传递了三级  search->header->search views结果页面
    onSearch(val){
      if(this.getLocation.longitude && this.getLocation.latitude){
        this.$http.get(`search/lng/${this.getLocation.longitude}/lat/${this.getLocation.latitude}/keyword/${val}/pageCount/1`)
          .then(({data})=>{
            if(data.status === '200'){
              this.list = data.data
            }
          }).catch(err=>{
            this.$vux.toast.show({
              type: 'warn',
              text: '搜索失败',
              time: 2000
            })
          })
      }else{
        this.$http.get(`search/lng/28.344229/lat/113.1872558/keyword/${val}/pageCount/1`)
          .then(({data})=>{
            if(data.status === '200'){
              this.list = data.data
            }
          }).catch(err=>{
            this.$vux.toast.show({
              type: 'warn',
              text: '搜索失败',
              time: 2000
            })
          })
      }
    }
  }
}
</script>

